﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

//请写一个方法，传入一个中心点，传入一个半径，用LineRender画一个圆出来
public class Lesson21_code1 : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        DrawLineRenderer(Vector3.zero, 5, 360);
    }

    public void DrawLineRenderer(Vector3 centerPos, float r, int pointNum)
    {
        //动态创建对象
        GameObject obj = new GameObject();
        obj.name = "R";
        LineRenderer line = obj.AddComponent<LineRenderer>();
        line.loop = true;
        line.positionCount = pointNum;

        //每个点间隔度数
        float angle = 360 / pointNum;
        for (int i=0; i<pointNum; i++)
        {
            //知识点
            //1.点加向量 相当于平移点
            //2.四元数 * 向量 相当于在 旋转向量
            line.SetPosition(i, centerPos + Quaternion.AngleAxis(angle * i, Vector3.up) * Vector3.forward * r);
        }
    }
}
